package fxana;
import fxana.DateCell;
import java.math.BigDecimal;

import mathwork.Mathwork;

public class RawDataCell extends DateCell{
	private Double	 StartValue=null;
	private Double	 HighValue=null;
	private Double	 LowValue=null;
	private Double	 EndValue=null;
	static final String FMT_DATA="%-7.2f";
	static final String FMT_DATA_STR="%-7s";

	public RawDataCell(String date,Double startv,Double highv,Double lowv,Double endv) {
		super(date);
		StartValue=startv;
		HighValue=highv;
		LowValue=lowv;
		EndValue=endv;		
	}

	public boolean IsDataOK(){
		if (HighValue.compareTo(StartValue)<0)		return false;
		if (HighValue.compareTo(EndValue)<0)		return false;
		if (LowValue.compareTo(StartValue)>0)		return false;
		if (LowValue.compareTo(EndValue)>0)			return false;
		
		return true;
	}
	public boolean IsIncreased(){
		if(EndValue.compareTo(StartValue)>=0){
			return true;
		}else{
			return false;		
		}
	}
		
	public void out(){
		System.out.print(GetFSRecDate()+ 
								  " "+Mathwork.Roundup(StartValue,2).toString()+
								  " "+Mathwork.Roundup(HighValue,2).toString()+
								  " "+Mathwork.Roundup(LowValue,2).toString()+
								  " "+Mathwork.Roundup(EndValue,2).toString()+"\n");
	}	
	
	public Double GetStartValue(){		return StartValue;	}
	public String GetFSStartValue(){ return String.format(FMT_DATA, StartValue);	}
	public Double GetHighValue(){		return HighValue;	}
	public String GetFSHighValue(){ return String.format(FMT_DATA, HighValue);	}
	public Double GetLowValue(){		return LowValue;	}
	public String GetFSLowValue(){ return String.format(FMT_DATA, LowValue);	}
	public Double GetEndValue(){		return EndValue;	}
	public String GetFSEndValue(){ return String.format(FMT_DATA, EndValue);	}
	public Double GetHighStart() {return this.HighValue-this.StartValue;}
	public Double GetStartLow() {return this.StartValue-this.LowValue;}
	public Double GetEndStart() {return this.EndValue-this.StartValue;}
	public Double GetHightLow() {return this.HighValue-this.LowValue;}
	
	public String GetFSDataValue(ParaFlag flag){
		String spliter=" ";
		if(flag.IsCFlagSet()){
			spliter=",";
		}
		return GetFSStartValue()+spliter+GetFSHighValue()+spliter+GetFSLowValue()+spliter+GetFSEndValue();
	}
	
	public Double GetAverage(){
		Double tmp=(StartValue + HighValue + LowValue +EndValue)/4;
		tmp=new BigDecimal(tmp).setScale(2,BigDecimal.ROUND_HALF_EVEN).doubleValue();
		return tmp;
	}
	
	public String GetFSAverage(){
		return String.format(FMT_DATA, GetAverage());
	}
}
